package com.example.chapter04;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;



public class ActionUriActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_action_uri);
        findViewById(R.id.btn_dial).setOnClickListener(this);
        findViewById(R.id.btn_my).setOnClickListener(this);
        findViewById(R.id.btn_sms).setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        Intent intent=new Intent();
        String phoneNo="123456";
        if (view.getId()==R.id.btn_dial){
            //指定意图的动作行为
            intent.setAction(Intent.ACTION_DIAL);
            Uri uri=Uri.parse("tel:"+phoneNo);
            intent.setData(uri);
            startActivity(intent);
        }
        if (view.getId()==R.id.btn_sms){
            //指定意图的动作行为
            intent.setAction(Intent.ACTION_SENDTO);
            Uri uri2=Uri.parse("smsto:"+phoneNo);
            intent.setData(uri2);
            startActivity(intent);
        }

        if (view.getId()==R.id.btn_my){
            intent.setAction("android.intent.action.NIN");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        }

    }
}